
function login() {
    var username = document.getElementById("ID").value;
    var password = document.getElementById("PASSWORD").value;
    if (username == "") {
        $.jGrowl("邮箱不能为空！", {header: '温馨提醒'});
    } else if (password == "") {
        $.jGrowl("密码不能为空！", {header: '温馨提醒'});
    } else {
        AjaxFunc();
    }
}

$(function () {
    $(window).keydown(function (even) {
        if (even.keyCode === 13) {
            login();
        }
    });
});

function AjaxFunc() {
    var username = document.getElementById("ID").value;
    var password = document.getElementById("PASSWORD").value;
    $.ajax({
        type: 'post',
        url: "/login.do",
        dataType: "json",
        data: {"email": username, "password": password},
        success: function (data) {
            if (data.success) {
                $.jGrowl("登录成功，欢迎回来");
                setTimeout(function () {
                    // 成功，进行跳转
                    location.href = "/user/list.do";
                }, 1500);
            } else {
                //不成功，提示
                $.jGrowl(data.errorMsg, {header: '温馨提醒'});
            }
        },
        error: function (xhr, type) {
            if (type){
                $.jGrowl("亲，您已登录，2S后跳转", {header: '温馨提醒'});
                setTimeout(function () {
                    location.href = "/user/list.do";
                }, 2000);
            } else {
                console.log(xhr,  type);
            }
        }
    });
}